import { getCategoryList } from "@/apis/Category";
import { onBeforeRouteUpdate, useRoute } from "vue-router";
import { onMounted, ref } from "vue";
export const useCategory = () => {
  // 获取面包屑导航数据
  const route = useRoute();
  const list = ref([]);
  const getCateList = async (id = route.params.id) => {
    const {
      data: { result },
    } = await getCategoryList(id);
    list.value = result;
  };
  onMounted(() => {
    getCateList();
  });

  //监听路由切换更换请求数据
  onBeforeRouteUpdate((to) => {
    getCateList(to.params.id);
  });
  return {
    list
  }
};
